package com.example.emos.wx.exception;

import lombok.Data;

/**
 * 服务（业务）异常如“ 账号或密码错误 ”，该异常只做INFO级别的日志记录 @see WebMvcConfigurer
 */
@Data
public class BusinessException extends RuntimeException {
    private StatusResult statusResult;
    private String code;
    private String msg;

    public BusinessException() {
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(String message, Exception e) {
        super(message, e);
    }

    public BusinessException(String code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public BusinessException(StatusResult statusResult) {
        super(statusResult.getMsg());
        this.statusResult = statusResult;
    }

    public BusinessException(StatusResult statusResult, Exception e) {
        super(statusResult.getMsg(), e);
        this.statusResult = statusResult;
    }

    public StatusResult getStatusResult() {
        return this.statusResult;
    }

    public void setResultMsg(StatusResult statusResult) {
        this.statusResult = statusResult;
    }

    public String getCode() {
        return this.statusResult == null ? this.code : this.statusResult.getCode();
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return this.statusResult == null ? this.msg : this.statusResult.getMsg();
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

}
